/*
 * Copyright (C) <2009>  <Matthew Dickinson>
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.pulsarwebdevelopment.concordance;

/**
 * Holds verse info (book, chapter, verse)
 * @author Matthew Dickinson
 * Last updated: 8/22/2009
 */
public class Verse implements Comparable<Verse>{


	private String bookName;
	private int bookIndex;
	private short chapter;
	private short verse;

	public Verse(int bookIndex, String book_name, short chapter, short verse){
		this.bookIndex = bookIndex;
		this.bookName = book_name;
		this.chapter = chapter;
		this.verse = verse;
	}

	public int compareTo(Verse alt) {
		//Verse alt = (Verse) arg;		//cast arg to a Verse
		if(alt.bookName.compareTo(this.bookName) < 0){ //from a earlier book
			return +1;
		}else{
			if(alt.bookName == this.bookName){
				if(alt.chapter < this.chapter){	// argument is from a earlier chapter
					return +1;
				}else{
					if(alt.chapter == this.chapter){	//verses are from the same chapter
						if(alt.verse < this.verse){	//argument is from a earlier verse
							return +1;
						}else{
							if(alt.verse == this.verse){ //verses are equivalent
								return 0;
							}else{						//argument is from a later verse
								return -1;
							}
						}
					}else{		//argument is from a later chapter
						return -1;
					}
				}
			}else{
				return -1; //arg is from a later book
			}
		}
	}

	public boolean equals(Object obj){
		if(obj instanceof Verse){
			if(this.compareTo((Verse) obj) == 0){
				return true;
			}
		}
		return false;
	}
	public String toString(){
		return bookName + " " + chapter + ":" +verse;
	}

	public short getVerse(){
		return verse;
	}

	public short getChapter(){
		return chapter;
	}

	public String getBookName(){
		return bookName;
	}

	public int getBookIndex(){
		return bookIndex;
	}
}
